<template>
	<view>
		<view class="change">
			<view class="change1">
				<u-field v-model="mobile" label="账户" placeholder="请填写手机号">
				</u-field>
				<u-field v-model="mobile1" label="原密码" placeholder="请输入支付密码">
				</u-field>
				<u-field v-model="mobile2" label="新密码" placeholder="请输入新密码">
				</u-field>
				<u-field v-model="mobile3" label="确认密码" placeholder="请再次输入密码">
				</u-field>
				<u-field v-model="code" label="验证码" placeholder="请填写验证码">
					<u-button size="mini" slot="right" type="success" @click="getCode">{{codeText}}</u-button>
				</u-field>
				<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
			</view>
			<view class="change2">
				<view class="change2-1">
					温馨提示：
				</view>
				<view class="change2-2">
					支付密码仅支持非连续性数字组合，请不要以常用组合，特殊日期作为密码。
				</view>
			</view>
			<view class="change3" @click="submitForm">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	import {
		changePassword,
		sendVerificationCode
	} from "../../API/myAccount.js"
	export default {
		data() {
			return {
				mobile: "",
				mobile1: '',
				mobile2: "",
				mobile3: "",
				code: '',
				codeText: ''
			}
		},
		methods: {
			onLoad(option) {
				this.mobile = option.cardnum
			},
			codeChange(text) {
				this.codeText = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					sendVerificationCode().then((res) => {
						console.log(res);
					}).catch((err) => {
						console.log(err);
					})
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 1000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			submitForm() {
				// 判空操作
				if (
					!this.mobile ||
					!this.mobile1 ||
					!this.mobile2 ||
					!this.mobile3 ||
					!this.code
				) {
					this.$u.toast("请填写完整信息");
					return;
				} else if (this.mobile2 != this.mobile3) {
					this.$u.toast("两次密码不一致");
				}
				changePassword({
					oldPayPassword: this.mobile1,
					newPayPassword: this.mobile2,
					confirmNewPayPassword: this.mobile3,
					verificationCode: this.code
				}).then((res) => {
					console.log(res);
				})
			}
		}
	}
</script>

<style>
	.change {
		background-color: #f7f7f7;
		height: 1650rpx;
	}

	.change1 {
		background-color: white;
	}

	.change2 {
		color: rgb(128, 128, 128);
		margin-top: 20rpx;
		width: 700rpx;
		margin-left: 30rpx;
	}

	.change3 {
		width: 700rpx;
		height: 80rpx;
		background-color: orange;
		border-radius: 10rpx;
		color: white;
		margin-top: 40rpx;
		text-align: center;
		line-height: 80rpx;
		margin-left: 20rpx;
	}
</style>